import { Injectable } from '@angular/core';
import { HttpClient } from "@angular/common/http";

import { GlobalSettingService } from '../services/global-setting.service';

@Injectable()
export class CategoryService {

  constructor(private http: HttpClient, private globalSetting: GlobalSettingService) { }

  public getList(): any {
    return this.http.get(this.globalSetting.getLibraryWebApiRootUrl() + 'category/list');
  }

  public create(category: any): any {
    let formData = new FormData();
    formData.append('name', category.name);
    formData.append('icon', category.icon);
    return this.http.post(this.globalSetting.getLibraryWebApiRootUrl() + 'category/create', formData);
  }

  public update(category: any): any {
    let formData = new FormData();
    formData.append('id', category.id);
    formData.append('name', category.name);
    formData.append('icon', category.icon);
    return this.http.post(this.globalSetting.getLibraryWebApiRootUrl() + 'category/update', formData);
  }

}
